package com.asset.service;

import com.asset.entity.User;
import com.asset.mapper.UserMapper;
import com.asset.vo.AjaxJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Service
public class UserService {
	@Autowired
	private UserMapper userMapper;
	public AjaxJson 	login(String username, String password, HttpServletRequest request) {
		User user = userMapper.getUser(username, password);
		if (user != null) {
			HttpSession session =request.getSession();
			session.setAttribute("user", user);
		 User user1 =(User) session.getAttribute("user");
			System.out.println(user1);
			AjaxJson ajaxJson = new AjaxJson();
			ajaxJson.setSuccess("true");
			ajaxJson.setMsg("登录成功");
			return ajaxJson;
		}else{
	        AjaxJson ajaxJson = new AjaxJson();
			ajaxJson.setSuccess("false");
			ajaxJson.setMsg("登录失败");
			return ajaxJson;
		}
	}
}
